package com.leo.train.business.controller.admin;

import com.leo.train.business.dto.DailySeatQueryDto;
import com.leo.train.business.entity.DailySeat;
import com.leo.train.business.service.DailySeatService;
import com.leo.train.business.vo.DailySeatVo;
import com.leo.train.common.resp.CommonResp;
import com.leo.train.common.resp.PageResult;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/admin/daily-seat")
public class DailySeatAdminController {
    @Autowired
    private DailySeatService dailySeatService;

    /**
     * 新增
     * @param dailySeat
     * @return
     */
    @PostMapping("/add")
    public CommonResp add(@Valid  @RequestBody DailySeat dailySeat) {
        dailySeatService.save(dailySeat);
        return new CommonResp<>();
    }

    /**
     *  修改
     *  @param dailySeat
     *  @return
     */
    @PostMapping("/update")
    public CommonResp update(@Valid @RequestBody DailySeat dailySeat) {
        dailySeatService.save(dailySeat);
        return new CommonResp<>();
    }

    /**
     * 删除
     * @param map
     * @return
     */
    @PostMapping("/delete")
    public CommonResp delete(@RequestBody Map<String,Long> map) {
        Long id = map.get("id");
        dailySeatService.deleteById(id);
        return new CommonResp<>();
    }

    /**
     * 查询座位列表
     * @param dailySeatQueryDto
     * @return
     */
    @GetMapping("/list")
    public CommonResp<PageResult<DailySeatVo>> list(DailySeatQueryDto dailySeatQueryDto) {
        PageResult<DailySeatVo> pageResult = dailySeatService.list(dailySeatQueryDto);
        return new CommonResp<>(pageResult);
    }

    /**
     * 详情
     * @param id
     */
    @GetMapping("/detail")
    public CommonResp<DailySeatVo> detail(@RequestParam Long id) {
        DailySeatVo dailySeatVo = dailySeatService.detail(id);
        return new CommonResp<>(dailySeatVo);
    }


}
